# @time     :2021/12/31
# @Author   :Simple
# @FileName :register_page
from selenium.webdriver.common.by import By

from common.element import GetElement


class RegisterPage:
    """
    注册页
    """
    name_input = GetElement(xpath="//input[@id='corp_name']", describe="corp_name输入框", wait=True)
    industry_btn = GetElement(
        xpath="//*[@class='qui_btn ww_btn ww_btn_Big ww_btn_Block ww_btn_Dropdown js_corp_industry_btn']",
        describe="行业输入框")
    scale_btn = GetElement(xpath="//div[@id='corp_scale_btn']/a", describe="scale_btn")
    manager_name_input = GetElement(id_="manager_name", describe="管理员姓名")
    register_tel_input = GetElement(id_="register_tel", describe="注册手机号")
    get_code_btn = GetElement(id_="get_vcode", describe="获取验证码")
    code_input = GetElement(id_="vcode", describe="验证码输入框")
    iagree_btn = GetElement(id_="iagree", describe="同意按钮")
    submit_btn = GetElement(id_="submit_btn", describe="提交按钮")

    def __init__(self, driver):
        self.driver = driver

    def register(self, company_name, industry_name, industry_itme, company_scale, manager_name, mobile):
        """
        注册企业微信
        :param company_name: 企业名称
        :param industry_name: 行业类型（规定数据），如：IT服务
        :param industry_itme: 行业类型-item（和'行业类型'相关联，规定数据），如：互联网和相关服务
        :param company_scale: 员工规模（规定数据），如：1-50人、51-100人
        :param manager_name: 管理员姓名
        :param mobile: 管理员手机号
        :return:
        """
        vcode = "1234"  # 验证码

        self.name_input.send_keys(company_name)
        self.industry_btn.click()
        self.driver.find_element(By.XPATH, f"//div[@data-name='{industry_name}']/a").click()
        self.driver.find_element(By.XPATH, f"//div[@data-name='{industry_itme}']/a").click()
        self.scale_btn.click()
        self.driver.find_element(By.XPATH, f"//span[contains(text(),'{company_scale}')]").click()
        self.manager_name_input.send_keys(manager_name)
        self.register_tel_input.send_keys(mobile)
        # self.get_code_btn.click()  # 获取验证码
        self.code_input.send_keys(vcode)
        self.iagree_btn.click()
        self.submit_btn.click()
        self.driver.get("https://work.weixin.qq.com/")
